<template>
  <div>
    <div class="component-window min flash" @click="min"></div>
    <div class="component-window full flash" @click="full"></div>
    <div class="component-window exit flash" @click="exit"></div>
  </div>
</template>

<script>
import app from '@/app'
import userModel from '@/model/user';
import accountModel from '@/model/account';

export default {
  setup() {
    // 当窗口关闭时
    window.onbeforeunload = () => {
      accountModel.logout()
    }

    return {
      min() {
        app.window.min()
      },

      full() {
        app.window.full()
      },

      async exit() {
        // 登出
        try{
          await userModel.logout()
        } catch (e) {
          console.log(e)
        }

        try{
          await accountModel.logout()
        } catch (e) {
          console.log(e)
        }

        // 清空，退出
        app.window.exit()
      }
    }
  }
}
</script>